package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.*;
import com.bcu.calculus.mapper.CheckAttendanceMapper;
import com.bcu.calculus.mapper.CheckMessageMapper;
import com.bcu.calculus.service.CheckAttendanceService;
import com.bcu.calculus.service.CheckMessageService;
import com.bcu.calculus.utils.CheckAttendanceUtil;
import com.bcu.calculus.utils.SendUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;


@Service
public class CheckAttendanceServiceImpl implements CheckAttendanceService {

    @Resource
    private CheckAttendanceMapper checkAttendanceMapper;


    @Override
    public Message<?> insertSelective(CheckAttendanceNumber checkAttendanceNumber) throws ParseException {
        String checkId = "CI" + SendUtil.genSendId();
        checkAttendanceNumber.setCheckId(checkId);
        CheckAttendance checkAttendance = CheckAttendanceUtil.change(checkAttendanceNumber);
        checkAttendance.setCheckUpdateTime(new Date());
        checkAttendance.setCheckCreateTime(new Date());
        return checkAttendanceMapper.insertSelective(checkAttendance)> 0 ? Message.success(null).add(checkId) : Message.fail(null);
    }

    @Override
    public Message<?> deleteByPrimaryKey(String checkId) {
        return checkAttendanceMapper.deleteByPrimaryKey(checkId)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateByPrimaryKeySelective(CheckAttendanceNumber checkAttendanceNumber) throws ParseException {
        //checkAttendanceNumber.setCheckUpdateTime(new Date());
        CheckAttendance checkAttendance = CheckAttendanceUtil.change(checkAttendanceNumber);
        checkAttendance.setCheckUpdateTime(new Date());
        return checkAttendanceMapper.updateByPrimaryKeySelective(checkAttendance)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<CheckAttendance>> selectAll() {
        return Message.success(null).add(checkAttendanceMapper.selectAll());
    }

    @Override
    public Message<List<CheckAttendance>> selectById(String checkId) {
        return Message.success(null).add(checkAttendanceMapper.selectById(checkId));
    }

    @Override
    public Message<List<CheckAttendance>> selectByCheckSemIdAndCheckListAndCheckListId(String checkSemId, String checkList, String checkListId) {
        return Message.success(null).add(checkAttendanceMapper.selectByCheckSemIdAndCheckListAndCheckListId(checkSemId,checkList,checkListId));
    }

}
